import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

sales = 146.87 # 销售额 (万)
profit = 14.27 # 利润额 (万)
profit_rate = (profit / sales) * 100  # 利润率计算

# 创建图表
plt.figure(figsize=(6, 6), facecolor='#2E4057')
ax = plt.gca()
ax.set_facecolor('#2E4057')

# 绘制圆环图
colors = ['#FF6F91', '#D9D9D9']
plt.pie(
    [profit_rate, 100 - profit_rate],
    radius=1,
    colors=colors,
    startangle=--47,
    wedgeprops={'width': 0.3, 'edgecolor': '#2E4057'}
)

# 中心文本
plt.text(0, 0.15, f"{profit_rate:.2f}%", ha='center', va='center', fontsize=24, color='white', weight='bold')
plt.text(0, -0.1, "利润率", ha='center', va='center', fontsize=20, color='white')

# 右侧文本信息
plt.text(1.2, 0.3, f"利润额(万)  {profit:.2f}", ha='left', va='center', fontsize=20, color='#FF6F91')
plt.text(1.2, 0.0, f"销售额(万)  {sales:.2f}", ha='left', va='center', fontsize=20, color='#FF6F91')
plt.text(1.2, 0.15, "/", ha='left', va='center', fontsize=20, color='white')

# 底部按钮样式文本
plt.text(0, -1.3, "利润额占比销售额", ha='center', va='center', fontsize=20, color='white',
        bbox=dict(facecolor='#2E4057', edgecolor='#4F81BD', boxstyle='round,pad=0.4', linewidth=2))

# 隐藏多余轴
ax.axis('equal')

# 调整布局
plt.tight_layout()

plt.savefig(r'D:\python charm\01\可视化\销售看板参考\图片\利润率.png')

plt.show()